<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>
<style>
img{

    width: 150px !important;
    height: 100px !important;
    border-radius: 0 !important;

}
</style>
<body class="gray-bg">
    <div class="ui-layout-west">
		<div class="main-content">
			<div class="box box-main">
				<div class="box-header">
					<div class="box-title">
						<i class="fa icon-grid"></i> 商品类目
					</div>
					<div class="box-tools pull-right">
					    <a type="button" class="btn btn-box-tool menuItem" href="#" onclick="channel()" title="商品类目"><i class="fa fa-edit"></i></a>
						<button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
						<button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
						<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新部门"><i class="fa fa-refresh"></i></button>
					</div>
				</div>
				<div class="ui-layout-content">
					<div id="tree" class="ztree"></div>
				</div>
			</div>
		</div>
	</div>
	
     <div class="container-div ui-layout-center">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<input type="hidden" id="categoryId" name="categoryId">
	                <input type="hidden" id="pid" name="pid">
					<div class="select-list">
						<ul>
							<li>
								商品名称：<input type="text" name="productName"/>
							</li>

							<li>
								商品型号：<input type="text" name="marque"/>
							</li>

							<li>
								仓库条码：<input type="text" name="barcode"/>
							</li>
							<li>
								状态:
								<select name="status" th:with="type=${@dict.getType('wechat_public_status')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.addMenuItem()" shiro:hasPermission="wechat:wechatProduct:add">
					<i class="fa fa-plus"></i> 添加商品
				</a>
				<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="wechat:wechatProduct:edit">
					<i class="fa fa-edit"></i> 修改商品
				</a>
				<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="wechat:wechatProduct:remove">
					<i class="fa fa-remove"></i> 删除商品
				</a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="wechat:wechatProduct:export">
						<i class="fa fa-download"></i> 导出商品信息
				 </a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:src="@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"></script>
	<script th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('wechat:wechatProduct:edit')}]];
        var removeFlag = [[${@permission.hasPermi('wechat:wechatProduct:remove')}]];
        var prefix = ctx + "wechat/wechatProduct";
        var product_status_datas = [[${@dict.getType('wechat_public_status')}]];
        
        $(function() {
		    var panehHidden = false;
		    if ($(this).width() < 769) {
		        panehHidden = true;
		    }
		    $('body').layout({ initClosed: panehHidden, west__size: 185 });
		    queryPublicList();
		    queryCategoryTree();
		});

        function queryPublicList() {
        	var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                modalName: "商品信息",
		        showExport: true,
		        //fixedColumns: true,
		        //fixedNumber: 8,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'productId', 
					title : '自动编号',
					visible: false
				},
				{
					field : 'pictureUrl', 
					title : '商品图片',
					sortable: true,
				    formatter: function(value, row, index) {
				        return "<a href='"+row.pictureUrl+"' target='_Blank'>"+$.table.imageView(value, "")+"</a>";
				    }
				},
				{
					field : 'title', 
					title : '标题',
					formatter: function(value, row, index) {
				        return $.table.tooltip(value);
				    }
				},
				{
					field : 'productName', 
					title : '商品名称',
					sortable: true
				},
				/* {
					field : 'marque', 
					title : '商品型号',
					sortable: true
				},
				{
					field : 'barcode', 
					title : '仓库条码',
					sortable: true
				},*/
				{
					field : 'productCategory.name', 
					title : '商品类别',
					sortable: true
				},
				{
					field : 'brandName', 
					title : '品牌编号',
					sortable: true
				},
				{
					field : 'price', 
					title : '商品价格',
					sortable: true,
		            formatter: function(value, row, index) {
		                return '<a href="#" onclick="priceDetail(\'' + row.productId + '\')">' + value + '</a>';
		            }
				},
				/* {
					field : 'marketPrice', 
					title : '市场价格',
					sortable: true
				},
				{
					field : 'costPrice', 
					title : '成本价格',
					sortable: true
				}, */
				{
					field : 'stock', 
					title : ' 库存量',
					sortable: true
				},
				/* {
					field : 'warningStock', 
					title : '告警库存',
					sortable: true
				}, 
				{
					field : 'integral', 
					title : '商品积分',
					sortable: true
				},*/
				
				{
					field : 'status', 
					title : '状态',
					sortable: true,
		            formatter: function(value, row, index) {
		            	return $.table.selectDictLabel(product_status_datas, row.status);
		            }
				},
				{
					field : 'createTime', 
					title : '创建时间',
					sortable: true
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.productId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.productId + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        }
        
        function queryCategoryTree()
		{
			var url = ctx + "wechat/wechatShopProductCategory/treeData";
			var options = {
		        url: url,
		        expandLevel: 2,
		        onClick : zOnClick
		    };
			$.tree.init(options);
			
			function zOnClick(event, treeId, treeNode) {
				$("#categoryId").val(treeNode.id);
				$("#pId").val(treeNode.pId);
				$.table.search();
			}
		}
		
		$('#btnExpand').click(function() {
			$._tree.expandAll(true);
		    $(this).hide();
		    $('#btnCollapse').show();
		});
		
		$('#btnCollapse').click(function() {
			$._tree.expandAll(false);
		    $(this).hide();
		    $('#btnExpand').show();
		});
		
		$('#btnRefresh').click(function() {
			queryDeptTree();
		});
		
		/*类目*/
		function channel() {
			var url = ctx + "wechat/wechatShopProductCategory";
			createMenuItem(url, "类目管理");
		}
		
		/*字典列表-详细*/
		function priceDetail(productId) {
		    var url = prefix + '/priceDetail/' + productId;
		    createMenuItem(url, "价格明细");
		}
    </script>
</body>
</html>